package com.zlq.cn.controller.api;


import com.zlq.cn.api.ApiMessage;
import com.zlq.cn.api.ApiParam;
import com.zlq.cn.entity.SuggestRecord;
import com.zlq.cn.entity.User;
import com.zlq.cn.service.un.SuggestRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * <p>
 * 反馈记录 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2020-09-01
 */
@RestController
@RequestMapping("/api/suggestRecord")
public class SuggestRecordController {
    @Autowired
    private SuggestRecordService suggestRecordService;

    @RequestMapping
    public Object suggestRecord(@RequestBody ApiParam apiParam, User loginUser,
                                @NotNull(message = "反馈内容不能为空") String content,
                                @NotNull(message = "意见类型") String type,
                                @NotNull(message = "联系方式") String phone,
                                String imgs) throws Exception {
        SuggestRecord suggestRecord = new SuggestRecord();
        suggestRecord.setImgs(imgs);
        suggestRecord.setContent(content);
        suggestRecord.setMobile(loginUser.getPhone());
        suggestRecord.setPhone(phone);
        suggestRecord.setType(type);
        suggestRecord.setSubmitdate(LocalDateTime.now());
        suggestRecord.setIsreply(0);
        suggestRecord.setUserid(loginUser.getId());
        suggestRecordService.save(suggestRecord);
        return ApiMessage.resultApiMessage("反馈成功");
    }
}

